#pragma once
#include "Player.h"

IntPtr2D Player::Move(MoveDir Direction)
{
	switch(Direction)
	{
	case UP:
		WorldPos.Y--;
		break;

	case DOWN:
		WorldPos.Y++;
		break;

	case LEFT:
		WorldPos.X--;
		break;

	case RIGHT:
		WorldPos.X++;
		break;
	}
	DrawPos.Set(WorldPos.X*ImgSize.X, WorldPos.Y*ImgSize.Y);
	return DrawPos, WorldPos;	
}

void Player::ResetPos()
{
	WorldPos.Set(0,0);
	DrawPos.Set(0,0);
}

void Player::RefreshPos()
{
	DrawPos.Set(WorldPos.X*ImgSize.X, WorldPos.Y*ImgSize.Y);
}

void Player::Draw()
{
	Img.Draw(DrawPos);
}

void Player::HandleControls()
{
	switch(E_EV.type)
	{
	case SDL_KEYDOWN:
		switch(E_EV.key.keysym.sym)
		{
		case SDLK_w:
			if(ControlsActive) Move(UP);
			break;

		case SDLK_s:
			if(ControlsActive) Move(DOWN);
			break;

		case SDLK_a:
			if(ControlsActive) Move(LEFT);
			break;

		case SDLK_d:
			if(ControlsActive) Move(RIGHT);
			break;

		case SDLK_SPACE:
			if(ControlsActive) ResetPos();
			break;

		case SDLK_ESCAPE:
			E_RUN = false;
			break;

		case SDLK_p:
		SwitchBoolState(ControlsActive);
			break;
		}
		break;
	}
}

Player::Player() {}

Player::Player(string FileName)
{
	Img.LoadSurface(FileName);
	Img.SetColorKey(255, 255, 255);

	WorldPos.Set(0,0);
	ImgSize = IntPtr2D(Img.Surface->w, Img.Surface->h);
	DrawPos.Set(WorldPos.X*ImgSize.X, WorldPos.Y*ImgSize.Y);

	ControlsActive = true;
}